(**
** Lattakia Compiler
** Columbia University COMS-4115
** Programming Languages and Translators
** Authors:
** Wael Salloum
**)
{ open Ast 
	open LatticeCreation
	open Latparser
	let length=0;; let  count=1;; let clone=2;; let reverse=3;; let return=4;; let loop=5;; let getlost=6;; 
	let labels=10;;
}					

rule token = parse
  [' ' '\t']	{ token lexbuf }	(* Whitespace *)
| ['\r' '\n']	{ incr_linenum lexbuf; token lexbuf }	(* Whitespace *)
| ".."		{ singleLineComment lexbuf }
| "**"		{ multiLineComment lexbuf }
| '('	{ pushNewSymbolTable(env); LPAREN }	| ')'	{ RPAREN }	(* Punctuation *)
| '{'	{ LBRACE }	| '}'	{ RBRACE }
| '['	{ LSQBRACKET }	| ']'	{ RSQBRACKET }
| '^' {CARET}
| '+'	{ PLUS }		| '-'	{ MINUS }
| '*'	{ TIMES }		| '/'	{ DIVIDE }
| '%'	{ PERCENT }

| '|'	{ PIPE }		| '~'	{ TILDE }
| '!'	{ EXCLAMATION }		| '?'	{ QUEST }
| ';'	{ SEMI 	}	| ':'	{ COLON 	}
| '@'	{ AT }
| '.' {DOT}
| "def" {DEF}

| '='	{ ASSIGN } | "?="	{ QUEST_ASSIGN }

| "=="	{ EQ }		| "!="	{ NEQ }
| "&&"	{ AND }		| "||"	{ OR }

| '<'	{ LT }		| '>'	{ GT }
| "<="	{ LEQ }		| ">="	{ GEQ }

| "let"		{ LET }

| "true"	{ TRUE }	| "false"	{ FALSE }
| "this"	{ THIS }	| "nil"	{ NIL }
| "epsilon"	{ EPSILON }
| "length"	{ PREDEFINED_LABEL(length) }	| "count"	{ PREDEFINED_LABEL(count) } 
| "clone" { PREDEFINED_LABEL(clone) } | "labels"	{ PREDEFINED_LABEL(labels) }
| "return" { PREDEFINED_LABEL(return) } | "loop" { PREDEFINED_LABEL(loop) }
| "getlost" { PREDEFINED_LABEL(getlost) }
| eof	{ EOF }

| '\"'([^'\"'])*'\"' as lxm { STRING_LITERAL(String.sub lxm 1 ((String.length lxm)-2)) }

| ('-')?['0'-'9']+'.'['0'-'9']+ as lxm { FLOAT(float_of_string lxm) }
| ['0'-'9']+ as lxm { INTEGER(int_of_string lxm) }
| ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| _ as char { addToErrorTable(LexUndefinedSymbol(Char.escaped char), None); NIL}

and singleLineComment = parse
 "\n"	{ token lexbuf }
| eof	{ EOF }
| _		{ singleLineComment lexbuf }

and multiLineComment = parse
 "**"	{ token lexbuf }
| eof	{ EOF }
| _		{ multiLineComment lexbuf }


